{ "cells": [ { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_19\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_19\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_19\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_19\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #19:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #19 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class Person {\n", " int x, y;\n", " float angle;\n", " \n", " Person(int x, int y) {\n", " this.x = x;\n", " this.y = y;\n", " this.angle = ranom;\n", " }\n", " void move() {\n", " this.angle = this.angle + .1; // these are in radians\n", " }\n", " \n", " void draw() {\n", " ellipse(this.x, this.y, 50, 50);\n", " rect(this.x - 25, this.y + 25, 50, 100);\n", " // left arm:\n", " quad(this.x - 25 - 10, this.y + 25,\n", " this.x - 25, this.y + 25,\n", " this.x - 25, this.y + 25 + 40,\n", " this.x - 25 - 10, this.y + 25 + 40);\n", "\n", " // right arm, draw relative to origin:\n", " float x1 = 0;\n", " float y1 = 0;\n", " float x2 = 10;\n", " float y2 = 0;\n", " float x3 = 10;\n", " float y3 = 40;\n", " float x4 = 0;\n", " float y4 = 40;\n", " \n", " pushMatrix();\n", " translate(this.x + 25, this.y + 25); // move to where you want it\n", " rotate(angle); // rotate it\n", " quad(x1, y1,\n", " x2, y2,\n", " x3, y3,\n", " x4, y4);\n", " popMatrix();\n", " }\n", "}\n", "\n", "Person[] people = new Person[5];\n", "\n", "void setup() {\n", " int i = 0;\n", " while (i < 5) {\n", " people[i] = new Person(int(random(500)), 100);\n", " i = i + 1; // i++\n", " }\n", " size(500, 300);\n", "}\n", "\n", "void draw() {\n", " background(128);\n", " for (int i=0; i < 5; i++) {\n", " people[i].draw();\n", " }\n", " text(\"Click to move arm\", 10, 20);\n", "}\n", "\n", "void mousePressed() {\n", " for (int i=0; i < 5; i++) {\n", " people[i].move();\n", " } \n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Calysto Processing", "language": "java", "name": "calysto_processing" }, "language_info": { "codemirror_mode": { "name": "text/x-java", "version": 2 }, "file_extension": ".java", "mimetype": "text/x-java", "name": "java" } }, "nbformat": 4, "nbformat_minor": 0 }